package com.mw.service;

import com.mw.domain.Comment;
import com.mw.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CommentService {

    @Autowired
    CommentRepository commentRepository;

    public List<Comment> getAllCommentByNid(String nid){
        return commentRepository.findAllByNid(nid);
    }

    public List<Comment> getAllCommentByUid(String uid){
        return commentRepository.findAllByUid(uid);
    }

    public void saveComment(Comment comment){
        commentRepository.save(comment);
    }

    public void delComment(int id){
        commentRepository.delete(commentRepository.findById(id));
    }

    public void delAllbyNid(String id){
        commentRepository.deleteAllByNid(id);
    }

}
